﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using System.Web.UI.WebControls;
using System.Web.UI;

public class PaginaBase : System.Web.UI.Page
{
    #region Llenar Controles

    public void ControlDataBind(IEnumerable _collection, GridView _gridView)
    {
        _gridView.DataSource = _collection;
        _gridView.DataBind();
    }

    public void ControlDataBind(IEnumerable _collection, DropDownList _gridView, string _dataValue, string _dataMember, bool _addSelectOne)
    {
        _gridView.DataSource = _collection;
        _gridView.DataValueField = _dataValue;
        _gridView.DataTextField = _dataMember;
        _gridView.DataBind();

        if (_addSelectOne)
            _gridView.Items.Insert(0, new ListItem("--Seleccione--", "0"));
        else
            _gridView.Items.Insert(0, new ListItem("--Todos--", "0"));
    }

    public void ControlDataBind(IEnumerable _collection, ListBox _listBox, string _dataValue, string _dataMember)
    {
        _listBox.DataSource = _collection;
        _listBox.DataValueField = _dataValue;
        _listBox.DataTextField = _dataMember;
        _listBox.DataBind();
    }

    public void ControlDataBind(IEnumerable _collection, RadioButtonList _radioButtonList, string _dataValue, string _dataMember)
    {
        _radioButtonList.DataSource = _collection;
        _radioButtonList.DataValueField = _dataValue;
        _radioButtonList.DataTextField = _dataMember;
        _radioButtonList.DataBind();
    }

    public void ControlDataBind(IEnumerable _collection, CheckBoxList _checkBoxList, string _dataValue, string _dataMember)
    {
        _checkBoxList.DataSource = _collection;
        _checkBoxList.DataValueField = _dataValue;
        _checkBoxList.DataTextField = _dataMember;
        _checkBoxList.DataBind();
    }

    #endregion

    #region Constantes

    public enum Tablas
    {
        Estados = 1,
        Fases = 4,
        Contacto = 7,
        TipoMuestra = 12,
        Direccion = 16,
        Laboratorios = 21
    }

    public enum Estados
    {
        Iniciado = 11,
        EnProceso = 3,
        Finalizado = 2,
        Cerrado = 15
    }

    public enum Analisis
    {
        Litologico = 1,
        Muestras = 2,
        Geomecanica = 3,
        Estructuras = 4
    }

    public enum Fases
    {
        Exploracion = 5,
        Explotacion = 6
    }

    public enum TipoLabor
    {
        Galeria = 2,
        Rampa = 7,
        Crucero = 8,
        Subnivel = 1,
        Ventana = 9,
        Estocada = 10,
        Tajo = 11,
        Chimenea = 12
    }

    public enum Direccion
    {
        Norte = 17,
        Este = 19,
        Oeste = 20,
        Sur = 18
    }

    public enum TipoMuestra { 
        Comun = 13,
        Duplicada = 14
    }

    public enum Laboratorios { 
        Interno = 22,
        Externo = 23
    }

    #endregion

    #region Utilitarios

    public string GenerarCodigoMuestraSondaje(string id)
    {
        string formato = "E000000";
        string generado = formato.Substring(0, formato.Length - id.Length) + id;
        return generado;
    }

    public void MostrarMensaje(string mensaje)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append(@"<script type='text/javascript'>");
        sb.Append("alert('" + mensaje + "');");
        sb.Append(@"</script>");
        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AddHideModalScript", sb.ToString(), false);
        
    }

    public void AbrirPopup(string idPopup)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append(@"<script type='text/javascript'>");
        sb.Append("$('#" + idPopup + "').modal('show');");
        sb.Append(@"</script>");
        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AddHideModalScript", sb.ToString(), false);
    }

    public void OcultarPopup(string idPopup)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append(@"<script type='text/javascript'>");
        sb.Append("$('#"+idPopup+"').modal('hide');");
        sb.Append(@"</script>");
        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AddHideModalScript", sb.ToString(), false);
    }

    #endregion

}